import {Component, Vue} from "vue-property-decorator";
@Component
export default class pageMixins extends Vue {
    protected orderList = [];
    protected loading = false;
    protected pageNum = 1;
    protected pageSize = 10;
    protected total = 0;
    protected getDataFromApi(params: any): Promise<any> {
        throw new Error('getDataFromApi must be implemented')
    }
    // 切换页码
    protected handleIndexChange(pageNum: number) {
        this.pageNum = pageNum;
        this.fetchData()
    }
    protected async fetchData() {
        try {
            const res = await this.getDataFromApi({
                pageNum: this.pageNum,
                pageSize: this.pageSize
            })
            if (res) {
                this.orderList = res.data
                this.total = res.total
            }
        } catch (error) {
            console.error(error)
        }
    }

    protected handlePageChange(page: number) {
        this.pageSize = page
        this.fetchData()
    }
}
